<?php

/**
 * Class Home
 *
 * Please note:
 * Don't use the same name for class and method, as this might trigger an (unintended) __construct of the class.
 * This is really weird behaviour, but documented here: http://php.net/manual/en/language.oop5.decon.php
 *
 */
class Esala extends Controller
{
    /**
     * PAGE: index
     * This method handles what happens when you move to http://yourproject/home/index (which is the default page btw)
     */
    public function index()
    {    	
        // debug message to show where you are, just for the demo
        // echo 'Message from Controller: You are in the controller home, using the method index()';
        require 'application/views/common/_header.php';
        require 'application/views/tours/esala.php';
        require 'application/views/common/_footer.php';
    }
    
    public function booknow()
    {
    	if($_SERVER["REQUEST_METHOD"] == "POST" && $_POST['email'] != "" && $_POST['name'] != ""){
    
    		$mail = new PHPMailer();
    		 
    		$subject = "Dalada Procession Booking For:".$_POST['name'];
    		
    		$description = "Arrival Date:".$_POST['arrival']."\r\n Departure Date:".$_POST['departure']."\r\n Adults Count:".$_POST['adults']."\r\n Kids Count:".$_POST['kids'];
    		
    		$body = $subject."\r\nEnquire Email Address :".$_POST['email']."\r\n\r\n".$description;
    		
    		$contact_model = $this->loadModel('ContactModel');
    		$contact_model->addADescription($_POST['name'],$_POST["email"],$subject,$description);
    		
    		$mail->IsSMTP();
    		$mail->SMTPAuth = true;
    		$mail->Host = SMTP_SERVER;
    		$mail->Port = SMTP_PORT;
    		$mail->SMTPSecure = 'tls'; //comment this when using server mail client In Production
    		$mail->Username = SMTP_USER;
    		$mail->Password = SMTP_PASS;
    		//$mail->SMTPDebug = 2;
    		//$mail->Debugoutput = 'html';
    		 
    		$mail->SetFrom(SMTP_EMAILFROM, 'Explore With Seventurers ');
    		$mail->Subject = $subject;
    		$mail->MsgHTML($body);
    		$mail->AddAddress(SMTP_EMAILTO, $_POST['name']);
    
    		if($mail->Send()) {
    			$info = "<h1 style='color:green;'>Email Sent Successfully!!</h1>";
    
    			//$contact_model = $this->loadModel('ContactModel');
    			//$contact_model->addADescription($_POST['name'],$_POST["email"],$subject,$description);
    
    		} else {
    			//echo "Mailer Error: " . $mail->ErrorInfo;
    			$info = "<h1 style='color:red;'>Email Sending Failed, Please Try Again Later!!</h1>";
    		}
    
    	} else {
    
    		$info = "<h2 style='color:red;'>Please Fill the Requierd Fields!!</h2>";    
    		
    	}
    	
    	require 'application/views/common/_header.php';
    	require 'application/views/tours/esala.php';
    	require 'application/views/common/_footer.php';    
    }
    
    public function question()
    {
    	if($_SERVER["REQUEST_METHOD"] == "POST" && $_POST['email'] != "" && $_POST['question'] != "" && $_POST['name'] != ""){
    
    		$mail = new PHPMailer();
    		 
    		$subject = "Dalada Procession Question From:".$_POST['name'];
    
    		$description = $_POST['question'];
    
    		$body = $subject."\r\nEnquire Email Address :".$_POST['email']."\r\n\r\n".$description;
    
    		$contact_model = $this->loadModel('ContactModel');
    		$contact_model->addADescription($_POST['name'],$_POST["email"],$subject,$description);
    
    		$mail->IsSMTP();
    		$mail->SMTPAuth = true;
    		$mail->Host = SMTP_SERVER;
    		$mail->Port = SMTP_PORT;
    		$mail->SMTPSecure = 'tls'; //comment this when using server mail client In Production
    		$mail->Username = SMTP_USER;
    		$mail->Password = SMTP_PASS;
    		//$mail->SMTPDebug = 2;
    		//$mail->Debugoutput = 'html';
    		 
    		$mail->SetFrom(SMTP_EMAILFROM, 'Explore With Seventurers ');
    		$mail->Subject = $subject;
    		$mail->MsgHTML($body);
    		$mail->AddAddress(SMTP_EMAILTO, $_POST['name']);
    
    		if($mail->Send()) {
    			$info = "<h1 style='color:green;'>Email Sent Successfully!!</h1>";
    
    			//$contact_model = $this->loadModel('ContactModel');
    			//$contact_model->addADescription($_POST['name'],$_POST["email"],$subject,$description);
    
    		} else {
    			//echo "Mailer Error: " . $mail->ErrorInfo;
    			$info = "<h1 style='color:red;'>Email Sending Failed, Please Try Again Later!!</h1>";
    		}
    
    	} else {
    
    		$info = "<h2 style='color:red;'>Please Fill the Requierd Fields!!</h2>";
    
    	}
    	 
    	require 'application/views/common/_header.php';
    	require 'application/views/tours/esala.php';
    	require 'application/views/common/_footer.php';
    }
}